package com.gl.order.controller;

import cn.hutool.core.lang.tree.Tree;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.gl.order.commom.ResultBean;
import com.gl.order.entity.TMenu;
import com.gl.order.entity.TUser;
import com.gl.order.entity.dto.MenuAddDto;
import com.gl.order.entity.dto.MenuPageDto;
import com.gl.order.security.model.SecurityUser;
import com.gl.order.service.TMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @Author: liangSY
 * @Date: 2021/6/24
 * @ClassName: MenuController
 * @Description: 菜单栏
 */
@Api(tags = "菜单栏管理")
@RestController
@RequestMapping("/menu")
public class MenuController {

    private TMenuService menuService;

    public MenuController(TMenuService menuService) {
        this.menuService = menuService;
    }

    @GetMapping("/all")
    @ApiOperation("获取所有获取菜单")
    public ResultBean<List<Tree<String>>> allMenu(){
        List<Tree<String>> menus = menuService.allMneu();
        return ResultBean.success(menus);
    }

    @PostMapping("/saveOrUpdate")
    @ApiOperation("添加菜单")
    public ResultBean saveOrUpdateMenu(@RequestBody @Valid MenuAddDto dto){
        menuService.saveOrUpdateMenu(dto);
        return ResultBean.success();
    }

    @GetMapping("/del")
    @ApiOperation("删除菜单")
    public ResultBean delMenu(@RequestParam("id") String id){
        menuService.delMenu(id);
        return ResultBean.success();
    }
}
